package com.jeesite.modules.stock.web;

import java.util.List;
import java.util.stream.Collectors;

import com.jeesite.modules.stock.dto.UserColumnCheckedChangeDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.jeesite.modules.stock.dto.UserColumnsAddDTO;
import com.jeesite.modules.stock.entity.UserColumnsEntity;
import com.jeesite.modules.stock.service.UserColumnsService;

@RestController
@RequestMapping("${adminPath}/usercolumns")
public class UserColumnsController {

    @Autowired
    private UserColumnsService userColumnsService;

    @PostMapping("updateColumnSn")
    public void updateColumnSn(@RequestBody UserColumnsAddDTO userColumnsAddDTO) {
        userColumnsService.updateColumnSn(userColumnsAddDTO);
    }

    @PostMapping("updateColumnChecked")
    public void updateColumnChecked(@RequestBody UserColumnCheckedChangeDTO dto) {
        userColumnsService.updateColumnChecked(dto);
    }

    @GetMapping("getUserColumns")
    public List<String> getUserColumns(String userId) {
        List<UserColumnsEntity> columns = userColumnsService.getUserColumns(userId);
        return columns.stream().map(item -> item.getColumnDataindex()).collect(Collectors.toList());
    }
}
